﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Fakebook.Shared;

namespace Fakebook
{
    public partial class _Default : System.Web.UI.Page
    {


        private string UploadImage()
        {
            HttpPostedFile postFile = fuImage.PostedFile;
            const string ImagesDir = "/Images/";
            string fileName = string.Empty;
            if (postFile != null)
            {
                fileName = string.Format("{0}{1}",
                    ImagesDir, postFile.FileName
                );
                postFile.SaveAs(HttpContext.Current.Server.MapPath(fileName));
                return fileName;
            }
            else
            {
                return null;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                dlAnswer.DataBind();
            }
        }

        protected void btnPost_Click(object sender, EventArgs e)
        {
            hfImage.Value = UploadImage();




            int result = postSource.Insert();
            txtPost.Text = string.Empty;
        }

        protected void dlAnswer_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {

            }
        }
    }
}
